package com.cjdes.recipes4u.dto;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.TreeSet;


import ae.javax.xml.bind.annotation.XmlAccessorType;
import ae.javax.xml.bind.annotation.XmlElement;
import ae.javax.xml.bind.annotation.XmlRootElement;
import ae.javax.xml.bind.annotation.XmlAccessType;

@XmlRootElement(namespace="www.cj-des.com/recipes4u/")
@XmlAccessorType(XmlAccessType.FIELD)
public class RecipeStore implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 6326931231978950694L;
	@XmlElement(name="recipe")
	private ArrayList<Recipe> recipeList;

	public ArrayList<Recipe> getRecipeList() {
		return recipeList;
	}

	public void setRecipeList(ArrayList<Recipe> recipeList) {
		this.recipeList = recipeList;
	}

	@Override
	public String toString() {
	return recipeList.toString();
	}

	public TreeSet<String> getDistinctRecipeTypes(){
		TreeSet<String> types = new TreeSet<String>();
		for (Recipe recipe : recipeList) {
			types.add(recipe.getType());
		}
		
		return types;
	}
	
	public ArrayList<Recipe> getRecipesByType(String type){
		ArrayList<Recipe> recipes = new ArrayList<Recipe>();
		for (Recipe recipe : recipeList){
			if (recipe.getType().equals(type)){
				recipes.add(recipe);
			}
		}
		return recipes;
	}
	
	public Recipe getRecipeByName(String name){
		Recipe recipe = null;
		for (Recipe r : recipeList){
			if (r.getName().equals(name)){
				recipe = r;
			}
		}
		return recipe;
	}

	
}
